package br.com.playonline.persistencia;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import br.com.playonline.domain.Bolao;
import br.com.playonline.domain.Sorteio;
import br.com.playonline.domain.TipoDeJogo;
import br.com.playonline.dto.SorteioDTO;

@Component
public class SorteioHibernateDAO extends HibernateDAOGenerico<Sorteio, Long> {

	@Autowired
	public SorteioHibernateDAO(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	public Sorteio findByTipoDeJogo(TipoDeJogo tipoDeJogo){
		List<Sorteio> sorteios = findByCriteria(Restrictions.eq("tipoDeJogo", tipoDeJogo));
		return sorteios != null && sorteios.size() == 1 ? sorteios.get(0) : null;
	}
	
	public List<Sorteio> findSorteios(){
		return findByCriteria(Restrictions.ge("dtSorteio",new Date()));
	}

	public static void main(String[] args) {
		System.out.println(new Date());
	}
	
	
}
